define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        Dialog = ALL.Dialog,
        METHOD = ALL.METHOD,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>是否确认将该藏品设置为停牌？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });

    var _vm = Init.initVue({
        data : {
            check: {},
            self: {
                col_id: '',
                type : 1,
                time_type: []
            },
        },
        methods: {
            submit : function() {
                var flag, obj,
                    item = _vm.self;

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                obj = {
                    type: 2,
                    col_id: item.col_id,
                    time_type: item.time_type[item.type].type,
                    start_time: item.time_type[item.type].start,
                    end_time: item.time_type[item.type].end
                };

                if (obj.start_time > obj.end_time || obj.start_time == obj.end_time) {
                    METHOD.alert("停牌开始时间不能早于结束时间，请重新设置。")
                    return;
                }

                _Dialog.showUI(function(i){
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax("tradesuspend/create",{data: JSON.stringify(obj) },{type : 'post'}).done(function(){
                            METHOD.loading.hide();
                            METHOD.alert("操作成功").done(function(){
                                window.location.href = "../control/stop.html";
                            });
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });


            }
        }
    });

    METHOD.loading.show();
    METHOD.ajax("tradesuspend/time_list",{type:2}).done(function(json){
        METHOD.loading.hide();
        _vm.self.time_type = json.data;
    }).fail(function(){
        METHOD.loading.hide();
    });

    _vm.self.col_id = METHOD.getQueryParms("cid") || "";

});

